package com.crossriver.crgis.cofo.util;

import java.io.File;

import javax.mail.internet.InternetAddress;

import org.apache.log4j.Logger;

import com.liferay.portal.kernel.mail.SMTPAccount;
import com.liferay.util.mail.MailEngine;
import com.liferay.util.mail.MailEngineException;

public class Emailer {
    private static final Logger logger = Logger.getLogger(Emailer.class);
    private static void send(
            InternetAddress from, InternetAddress[] to, InternetAddress[] cc,
            InternetAddress[] bcc, InternetAddress[] bulkAddresses,
            String subject, String body, boolean htmlFormat,
            InternetAddress[] replyTo, String messageId, String inReplyTo,
            File[] attachments)
        throws MailEngineException {
        
        SMTPAccount smtpAccount = null;
        
        MailEngine.send(
                from,to, cc,
                 bcc, bulkAddresses,
                subject, body, htmlFormat,
                replyTo, messageId, inReplyTo,
                attachments,smtpAccount);

    }    

    public static void sendEmail(final String from, final String to,
            final String bcc, final String subject, final String body,
            final File[] attachments) throws Exception {

        InternetAddress[] toS = new InternetAddress[] { new InternetAddress(to) };
        InternetAddress fromS = new InternetAddress(from);
        InternetAddress[] bccS = null;
        if (bcc != null)
            bccS = new InternetAddress[] { new InternetAddress(bcc) };

        InternetAddress[] cc = null;
        InternetAddress[] bulkAddresses = null;
        boolean htmlFormat = true;
        InternetAddress[] replyTo = null;
        String messageId = null;
        String inReplyTo = null;

        Emailer.send(fromS, toS, cc, bccS, bulkAddresses, subject, body,
                htmlFormat, replyTo, messageId, inReplyTo, attachments);
    }
}